# -*- coding: utf-8 -*-
#!/usr/bin/env python
 
import urllib
import base64
import json

#client_id 为官网获取的AK， client_secret 为官网获取的SK
client_id = 'z0pmPkifUs3MxMLRLOIFCA75'
client_secret = 'klAXTwvE5dW45jlS7fpRORTx0txFkKfz'
 
#获取token
def get_token():
    host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + client_id + '&client_secret=' + client_secret
    request = urllib.request.Request(host)
    request.add_header('Content-Type', 'application/json; charset=UTF-8')
    response = urllib.request.urlopen(request)
    token_content = response.read()
    if token_content:
        token_info = json.loads(token_content)
        token_key = token_info['access_token']
    return token_key
